/**
 * 
 */
var Mediator = function() {
    var _msg = {};

    return {
        register: function(type, action) {
            if (_msg[type])
                _msg[type].push(action);
            else {
                _msg[type] = [];
                _msg[type].push(action);
            }
        },
        send: function(type) {
            if(_msg[type]) {
                for(var i = 0, len = _msg[type].length; i < len; i++) {
                    _msg[type][i] && _msg[type][i]();
                }
            }
        }
    };
}();

// 单元测试
Mediator.register('demo', function() {
    console.log('first');
});
Mediator.register('demo', function() {
    console.log('second');
});
Mediator.send('demo');

/**
 * 显隐导航小组件
 * @param {*} mod 
 * @param {*} tag 
 * @param {*} showOrHide 
 */
var showHideNavWidget = function(mod, tag, showOrHide) {
    var mod = document.getElementById(mod),
        tag = mod.getElementsByTagName(tag),
        showOrHide = (!showOrHide || showOrHide == 'hide') ? 'hidden' : 'visible';
    for (var i = tag.length - 1; i >= 0; i--) {
        tag.style.visibility = showOrHide;
    }
}


